/* lock parameters down so we can point to themn */
for (i=0;i<paramPtr->paramCount;i++) {
MoveHHi(paramPtr->params[i]);
HLock(paramPtr->params[i]);
}
/* get the parameters */
theContainer = paramPtr->params[0]; /* the container */
oldString = *(paramPtr->params[1]); /* the target string */
newString = *(paramPtr->params[2]); /* the replace string */
if (paramPtr->paramCount>3) { /* case sensitivity flag */
casePtr = *(paramPtr->params[3]);
strcpy(paramStr,casePtr);
}
else strcpy(paramStr,"");
ucase(paramStr);
if (strcmp(paramStr,"TRUE")==0)
caseSensitive = TRUE;
else caseSensitive = FALSE;
ReplaceInvisible();
/* assemble the return string */
paramPtr->returnValue = resultH;
for (i=0;i<paramPtr->paramCount;i++) HUnlock (paramPtr->params[i]);
return;
}
pascal void main(paramPtr)
XCmdBlockPtr paramPtr;
/* this is the entry point for the XFCN */
{
RememberA0();
SetUpA4(); /* to access globals */
Replace(paramPtr);
RestoreA4();
return;
}
-- part contents for card part 9
----- text -----
Replace version 1.2d1.c
Roger Brown
Replace is an XFCN that replaces all occurrences of specified target text with new text in a HyperCard container. The input is a container,
the old text, the new text, and a case sensitivity flag. The output is an edited copy of the container data.
This version does not support wildcards or pattern matching, and does not allow the user to verify each replacement. We plan to add these features in a later version, so the source for this utilizes toolbox TextEdit to do the replacement in an off-screen port. This is not the most efficient method for this particular XFCN, but it serves as a precursor to later development. The operation is still fairly fast.
This XFCN is best used as part of scripts that identify the containers (scripts, fields, globals) to be edited. For example, the SearchScript utility shipped with HyperCard could be modified to be a ReplaceScript utility by replacing "edit the script of" with this XFCN.
INVOKING Replace
get Replace(container,oldText,newText,
caseSens)
where container is any HyperCard container
oldText is the text to be replaced
newText is the text to replace with
caseSens is an option flag indicating if
the replacement will be case sensitive
EXAMPLE
ex. put Replace(the script of this card,"
myglobal","MyGlobal",false) into the
script of this card)
This example will correct the upper case appearance of all references to MyGlobal.
REVISION HISTORY
1.2d0.c First public release. Non-verify version.
1.2d1 3/30/90 Fixed hang when replacing any text with a null string. Compiled with Think C version 4.0.